package org.fuyd.dao;

import java.util.List;

import org.fuyd.model.IdCard;
import org.fuyd.model.Person;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class IdCardDaoImpl implements IdCardDao {
  private HibernateTemplate hibernateTemplate;

  public HibernateTemplate getHibernateTemplate() {
    return hibernateTemplate;
  }

  public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
    this.hibernateTemplate = hibernateTemplate;
  }

  public void add(IdCard idCard) {
    hibernateTemplate.save(idCard);
  }

  public IdCard findById(int id) {
    List<?> list = hibernateTemplate.find("from IdCard i where i.id = ?", id);
    return (IdCard) list.get(0);
  }

  public IdCard findByPerson(Person person) {
    List<?> list = hibernateTemplate.find("from IdCard i where i.person.id = ?", person.getId());
    return (IdCard) list.get(0);
  }

}
